package com.common.hbase.domain;

import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class GetDomain {

    private String tableName;

    private Get get;

    public GetDomain(String tableName, String rowKey) {

        this.tableName = tableName;

        get = new Get(Bytes.toBytes(rowKey));

    }

    public String getTableName() {
        return tableName;
    }

    public Get getGet() {
        return get;
    }

    public void setGet(Get get) {
        this.get = get;
    }

    public GetDomain addFamily(String columnFamily){
        get.addFamily(Bytes.toBytes(columnFamily));
        return this;
    }

    public GetDomain addColumn(String columnFamily, String... fields){
        if (fields==null||fields.length<=0){
            if (!columnFamily.isEmpty()){
                addFamily(columnFamily);
            }
        }else{
            if (!columnFamily.isEmpty()){
                for (String field : fields) {
                    get.addColumn(Bytes.toBytes(columnFamily), Bytes.toBytes(field));
                }
            }else{
                System.out.println("Error : columnFamily NotNull");
            }
        }
        return this;
    }

    public GetDomain setVersion(){
        get.setMaxVersions();
        return this;
    }

    public GetDomain setVersion(int version){
        try {
            get.setMaxVersions(version);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return this;
    }
}
